﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;



namespace DAO
{
    public class KhuVucDAO
    {
        public static DataTable ListKhuVuc()
        {
            string sql = string.Format("select * from KHUVUC");
            return DataProvider.ExcuteQuery(sql);
        }
        public static int Themkhuvuc(KhuVucDTO kv)
        {
            string sql = string.Format("Insert into KHUVUC(TENKV,SOLUONGBANTOIDA) Value(N'{0}','{1}')", kv.Tenkv, kv.MaxBan);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int Xoakhuvuc(int makv)
        {
            string sql = string.Format("delete KHUVUC where MAKV='{0}'", makv);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static DataTable GetTenKV(int makv)
        {
            string sql = string.Format("select TENKV FROM KHUVUC WHERE MAKV={0}", makv);
            return DataProvider.ExcuteQuery(sql);
        }
        public static int CheckNull(int makv)
        {
            string sql = string.Format("select * from BAN where MAKV={0}", makv);
            DataTable dt = DataProvider.ExcuteQuery(sql);

            if (dt == null)
                return 1;
            return 0;

        }
        public static int CheckFull(int makv)
        {
            string sql = string.Format("select * from BAN where MAKV={0}", makv);
            DataTable dt = DataProvider.ExcuteQuery(sql);
            string sql1 = string.Format("select SOLUONGBANTOIDA from KHUVUC where MAKV={0}", makv);
            DataTable dt1 = DataProvider.ExcuteQuery(sql1);
            int max = int.Parse(dt1.Rows[0]["SOLUONGBANTOIDA"].ToString());
            if (dt.Rows.Count == max)
                return 1;
            return 0;
        }
        public static int Delete(int makv)
        {
            string sql = string.Format("delete * from KHUVUC where MAKV={0}", makv);
            return DataProvider.ExcuteNonQuery(sql);

        }
    }
}
